﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model = eShop.Model;
using Entity = eShop.DataAccess.Entity;


namespace eShop.DataAccess.Converter
{
    public class OrderItemConverter
    {
        public static Model.OrderItemCollection ConvertToModelObject(List<Entity.OrderItem> entities)
        {
            Model.OrderItemCollection models = new Model.OrderItemCollection();
            foreach (Entity.OrderItem entity in entities)
            {
                models.Add(ConvertToModelObject(entity));
            }
            return models;
        }

        public static List<Entity.OrderItem> ConvertToEntity(Model.OrderItemCollection models)
        {
            List<Entity.OrderItem> entities = new List<Entity.OrderItem>();
            foreach (Model.OrderItem model in models)
            {
                entities.Add(ConvertToEntity(model));
            }
            return entities;
        }

        public static Model.OrderItem ConvertToModelObject(Entity.OrderItem entity)
        {
            if (entity == null) return null;
            Model.OrderItem model = new Model.OrderItem();
            model.Id = entity.Id;
            model.OrderId = entity.OrderId;
            model.ProductId = entity.ProductId;
            model.ProductName = entity.ProductName;
            model.ProductDescription = entity.ProductDescription;
            model.ProductDefaultImage = entity.ProductDefaultImage;
            model.StockId = entity.StockId;
            model.StockDescription = entity.StockDescription;
            model.UnitPrice = entity.UnitPrice;
            model.UnitWeight = entity.UnitWeight;
            model.Quantity = entity.Quantity;
            return model;
        }

        public static Entity.OrderItem ConvertToEntity(Model.OrderItem model)
        {
            Entity.OrderItem entity = new Entity.OrderItem();
            entity.Id = model.Id;
            entity.OrderId = model.OrderId;
            entity.ProductId = model.ProductId;
            entity.ProductName = model.ProductName;
            entity.ProductCode = model.ProductCode;
            entity.ProductDescription = model.ProductDescription;
            entity.ProductDefaultImage = model.ProductDefaultImage;
            entity.StockId = model.StockId;
            entity.StockDescription = model.StockDescription;
            entity.UnitPrice = model.UnitPrice;
            entity.UnitWeight = model.UnitWeight;
            entity.Quantity = model.Quantity;
            return entity;
        }
    }
}
